package gases.as3.librarys.core.display
{
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import gases.as3.librarys.core.Interface.IDispose;
	import gases.as3.librarys.core.managers.GEventManager;
	
	/**
	 * 基本容器类 
	 * @author guwanyuan
	 * 
	 */	
	public class GDisplayContainer extends Sprite implements IDispose
	{
		private var _event:GEventManager;
		private var _viewEvent:GEventManager;
		private var _Gwidth:Number = Infinity;
		private var _Gheight:Number = Infinity;
		private var _Gx:Number;
		private var _Gy:Number;
		
		private var _leftPadding:int = 0;
		private var _rightPadding:int = 0;
		private var _topPadding:int = 0;
		private var _bottomPadding:int = 0;
		
		private var _xOffset:int = 0;
		private var _yOffset:int = 0;
		
		public function GDisplayContainer() 
		{
			initialize();
		}
		
		/**
		 * 初始化
		 */
		protected function initialize():void
		{
			_event = new GEventManager();
			_viewEvent = new GEventManager(this);
		}
		
		/**
		 * 设置内部边缘空隙,一个4个值的数组
		 * 顺序为左上右下
		 */
		public function set padding(value:Rectangle):void 
		{
			_leftPadding = value.x;
			_rightPadding = value.y;
			_topPadding = value.width;
			_bottomPadding = value.height;
			
		}
		
		/**
		 * 相对对齐目标的偏移
		 */
		public function set offset(p:Point):void 
		{
			_xOffset = p.x;
			_yOffset = p.y;
		}
		
		public function get leftPadding():int { return _leftPadding; }
		
		public function get rightPadding():int { return _rightPadding; }
		
		public function get topPadding():int { return _topPadding; }
		
		public function get bottomPadding():int { return _bottomPadding; }
		
		public function get xOffset():int { return _xOffset; }
		
		public function get yOffset():int { return _yOffset; }
		
		/**
		 * 非显示列表事件管理,建议不需要经过显示列表的事件,以此为调度
		 */
		public function get event():GEventManager
		{
			return _event;
		}
		
		/**
		 * 经过显示列表的事件管理,建议所有的显示列表事件都以此为基础监听
		 */
		public function get viewEvent():GEventManager 
		{ 
			return _viewEvent; 
		}
		
		/**
		 * 预设大小, 提前站位用 
		 * @return 
		 * 
		 */		
		public function get Gwidth():Number 
		{ 
			if (_Gwidth == Infinity)
				return width;
			return _Gwidth; 
			
		}
		
		/**
		 * 预设大小, 提前站位用 
		 * @return 
		 * 
		 */		
		public function set Gwidth(value:Number):void 
		{
			_Gwidth = value;
		}
		
		/**
		 * 预设大小, 提前站位用 
		 * @return 
		 * 
		 */		
		public function get Gheight():Number 
		{
			if (_Gheight == Infinity)
				return height;
			return _Gheight; 
		}
		
		/**
		 * 预设大小, 提前站位用 
		 * @return 
		 * 
		 */		
		public function set Gheight(value:Number):void 
		{
			_Gheight = value;
		}
		
		/**
		 * 布局时使用的 
		 * @return 
		 * 
		 */		
		public function get Gx():Number 
		{ 
			return _Gx; 
		}
		
		/**
		 * 布局时使用的 
		 * @return 
		 * 
		 */	
		public function set Gx(value:Number):void 
		{
			_Gx = value;
		}
		
		/**
		 * 布局时使用的 
		 * @return 
		 * 
		 */	
		public function get Gy():Number 
		{ 
			return _Gy; 
		}
		
		/**
		 * 布局时使用的 
		 * @return 
		 * 
		 */
		public function set Gy(value:Number):void 
		{
			_Gy = value;
		}
		
		/**
		 * 清除自身显示列表内的显示对象
		 */
		public function clear():void
		{
			while (this.numChildren > 0)
				this.removeChildAt(0);
		}
		
		/**
		 * 销毁函数
		 */
		public function dispose():void
		{
			clear();
			this.graphics.clear();
			this.parent && this.parent.removeChild(this);
			_event.dispose();
			_event = null;
			_viewEvent.dispose();
			_viewEvent = null;
		}
		
	}
}






